﻿using UnityEngine;
using System.Collections;

public class cloud_generator : MonoBehaviour 
{
	public Transform cloud;
	private Vector3 spawnPos;
	private Vector3 posX = new Vector3(25f,15f,1f);
	private Vector3 velocity = new Vector3(10f,10f,10f);
	private float counter = 0;
	private Vector3 player;
	
	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		player = GameObject.FindGameObjectWithTag("Cloud").transform.position; 
	
		spawnPos.z = 13f;
		spawnPos.x = Random.Range(-20f, 30f);  //-20 ATÉ 30
		spawnPos.y = Random.Range(3f, 10f);  // 3 até 10
		
		transform.position += velocity;
		
		if(counter <= 10)
		{
			Instan();
		}
		
		//Random.Range(minSize.x, maxSize.x),
		
		if(transform.position.x > 15f)
		{
			Destroy(this);
			counter--;
		}	
		
	}
	
	void Instan()
	{
		Instantiate(cloud, spawnPos, Quaternion.Euler(-1.6f, -180f, 0));
		counter++;
	}
}
